<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">名称</label>
        <el-input v-model="query.holidaysName" clearable placeholder="名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.configType" clearable filterable
                   placeholder="请选择" style="width: 185px;" class="filter-item" @change="crud.toQuery" >
          <el-option
            v-for="item in dict.config_type"
            :key="item.id"
            :label="item.label"
            :value="item.value" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="名称" prop="holidaysName">
            <el-input v-model="form.holidaysName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="时间类型" prop="configType">
            <el-select v-model="form.configType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.config_type"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="星期" v-if="form.configType == '1'" prop="specifyTheWeek">
            <el-select v-model="form.specifyTheWeek" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.specify_the_week"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <template v-if="form.configType == '0'">
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker style="width: 370px;"
                              v-model="form.startTime"
                              type="datetime"
                              value-format='yyyy-MM-dd HH:mm:ss'
                              placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker style="width: 370px;"
                              v-model="form.endTime"
                              type="datetime"
                              value-format='yyyy-MM-dd HH:mm:ss'
                              placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
          </template>
          <template v-else>
            <el-form-item label="开始时间" prop="startTime">
              <!--<el-input v-model="form.startTime" style="width: 370px;" />-->
              <el-time-picker
                v-model="form.startTime"
                format="HH:mm"
                value-format='HH:mm'
                placeholder="任意时间点" style="width: 370px;">
              </el-time-picker>
            </el-form-item>
            <el-form-item label="结束时间" prop="endTime">
              <el-time-picker
                v-model="form.endTime"
                format="HH:mm"
                value-format='HH:mm'
                placeholder="任意时间点" style="width: 370px;">
              </el-time-picker>
            </el-form-item>
          </template>
          <el-form-item label="备注说明">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="holidaysName" label="名称" />
        <el-table-column prop="configType" label="时间类型">
          <template slot-scope="scope">
            {{ dict.label.config_type[scope.row.configType] }}
          </template>
        </el-table-column>
        <el-table-column prop="specifyTheWeek" label="星期">
          <template slot-scope="scope">
            {{ dict.label.specify_the_week[scope.row.specifyTheWeek] }}
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="开始时间" />
        <el-table-column prop="endTime" label="结束时间" />
        <el-table-column prop="remark" label="备注说明" />
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','factoryPlanHaltProduction:edit','factoryPlanHaltProduction:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudFactoryPlanHaltProduction from '@/api/factory/factoryPlanHaltProduction'
  import CRUD, { presenter, header, form, crud } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'

  const defaultForm = { id: null, templateCode: null, holidaysName: null, configType: '0', startTime: null, endTime: null, remark: null, createBy: null, createTime: null, updateBy: null, updateTime: null,specifyTheWeek:null }
  export default {
    props: [
      "modelCode"
    ],
    name: 'FactoryPlanHaltProduction',
    components: { pagination, crudOperation, rrOperation, udOperation },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    dicts: ['config_type','specify_the_week'],
    cruds() {
      return CRUD({ title: '计划停产时间', url: 'api/factoryPlanHaltProduction', idField: 'id', sort: 'id,desc', crudMethod: { ...crudFactoryPlanHaltProduction }})
    },
    watch: {
      modelCode(value) {
        this.queryPage(value)
      }
    },
    data() {
      return {
        templateCode:"",
        permission: {
          add: ['admin', 'factoryPlanHaltProduction:add'],
          edit: ['admin', 'factoryPlanHaltProduction:edit'],
          del: ['admin', 'factoryPlanHaltProduction:del']
        },
        rules: {
          templateCode: [
            { required: true, message: '所属模型不能为空', trigger: 'blur' }
          ],
          holidaysName: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ],
          configType: [
            { required: true, message: '时间类型不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          specifyTheWeek: [
            { required: true, message: '星期不能为空', trigger: 'blur' }
          ]
        },
        queryTypeOptions: [
          { key: 'templateCode', display_name: '所属模型' },
          { key: 'holidaysName', display_name: '名称' },
          { key: 'configType', display_name: '时间类型' }
        ]
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        this.crud.params.templateCode = this.templateCode;
        return true
      },
      //提交前
      [CRUD.HOOK.beforeSubmit]() {
        this.form.templateCode = this.templateCode;
        console.log(this.form);
        return true
      },
      queryPage(code){
        this.templateCode = code;
        this.crud.toQuery();
      },
    }
  }
</script>

<style scoped>

</style>
